<?php
/**
 * 退租(租满即送)
 * User: tengyu
 * Date: 2017/10/30
 * Time: 13:12
 */?>
@extends('common.common')
@section('title',$param['title'])
@section('css')
    <link rel="stylesheet" href="{{asset('/css/applyService_zu.css')}}">
@endsection
@section('js')
    <script type="text/javascript" src="{{asset('/js/applyServie_zu.js')}}"></script>
    <script>
        /**
         * 商品下单数量变更-
         * @cartid当前在租订单详情id
         */
        var rentback_fix = $("input[name='rentback_fix']").val();//固定租金
        var rentback_nimb = $("input[name='rentback_nimb']").val();//随租租金
        var rentback_amount = $("#rentback_bill .money:nth-child(3)").text();//租金(用户需还欠单)
        function decreback(cartid)
        {
            var num = $("#rentback_num").text();
            var rentback_num = $("input[name='rentback_num']").val();
            if(num-1<1){
                alert('退租数量已达下限');
            }else{
                num = num-1;
                $("#rentback_num").text(num);
                /**违约金计算*/
                var back_bond_1 = (rentback_fix*num*18*0.05).toFixed(2);
                $("#back_bond_t1 .money:nth-child(3)").text(back_bond_1);
                var amount_1 = (back_bond_1*1+rentback_amount*1);
                $("#back_amount_t1 .money:nth-child(3)").text(amount_1);
                /**转租押金*/
                 var back_bond_2 = rentback_nimb*num*2;
                $("#back_bond_t2 .money:nth-child(3)").text(back_bond_2);
                var amount_2 = back_bond_2*1+rentback_amount*1;
                $("#back_amount_t2 .money:nth-child(3)").text(amount_2);
            }
        }
        /**
         * 商品下单数量变更+
         * @cartid当前在租订单详情id
         */
        function increback(cartid)
        {
            var rentback_num = parseInt($("input[name='rentback_num']").val());
            var num = parseInt($("#rentback_num").text());
            num = num+1;
            if(num>rentback_num){
                alert('退单数量超出当前在租数量!');
                return false;
            }else{
                $("#rentback_num").text(num);
                /**违约金计算*/
                var back_bond_1 = (rentback_fix*num*18*0.05).toFixed(2);
                $("#back_bond_t1 .money:nth-child(3)").text(back_bond_1);
                var amount_1 = back_bond_1*1+rentback_amount*1;
                $("#back_amount_t1 .money:nth-child(3)").text(amount_1);
                /**转租押金*/
                var back_bond_2 = rentback_nimb*num*2;
                $("#back_bond_t2 .money:nth-child(3)").text(back_bond_2);
                var amount_2 = back_bond_2*1+rentback_amount*1;
                $("#back_amount_t2 .money:nth-child(3)").text(amount_2);
            }
        }
        /**选择付款方式,记录选择*/
        function rentback_type(type)
        {
            $("input[name='outrent_type']").attr('value',type)
        }
        /***支付执行建表语句*/
        /**处理退租需求逻辑【租满】*/
        function dorentback_type_fix()
        {
            /**订单id*/
            var order_id = $("input[name='order_id']").val();
            /**退租订单详情id*/
            var order_details_id = $("input[name='order_details_id']").val();
            /**退租订单详情单号*/
            var details_orderNo = $("input[name='details_orderNo']").val();
            /**退租商品id*/
            var fitment_details_id = $("input[name='details_fitment_id']").val();
            /**退租商品数量*/
            var fitment_details_number = $("#rentback_num").text();
            /**商品租满即送租金*/
            var rentback_fix = $("input[name='rentback_fix']").val();
            /**商品随租租金*/
            var rentback_nimb = $("input[name='rentback_nimb']").val();
            /**商品所需信用额度值*/
            var rentback_bond = $("input[name='rentback_bond']").val();
            /**订单关联地址di*/
            var adr_id = $("input[name='adr_id']").val();
            /**退租需支付金额*/
            var outrent_bill = rentback_amount;
            /**退租去向*/
            var outrent_type = $("input[name='outrent_type']").val();
            if(outrent_type<2){ //单纯退租家具
                /**退租需支付违约金或转租押金*/
                var outrent_bond = $("#back_bond_t1 .money:nth-child(3)").text();
                /**退租需支付总费用*/
                var outrent_amount = $("#back_amount_t1 .money:nth-child(3)").text();
                /**退租去向*/
                var outrent_type = 1;
            }else{//转租到随租随还
                /**退租需支付违约金或转租押金*/
                var outrent_bond = $("#back_bond_t2 .money:nth-child(3)").text();
                /**退租需支付总费用*/
                var outrent_amount = $("#back_amount_t2 .money:nth-child(3)").text();
                /**退租去向【退租去向,1退租,2转随租,3转租满即送】*/
                var outrent_type=2;
            }
            $.ajax({
                url:'/user/dorentback',
                type:'post',
                headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' },
                data:{
                    'type':2,
                    'order_id':order_id,'order_details_id':order_details_id,'details_orderNo':details_orderNo,'fitment_details_id':fitment_details_id,
                    'fitment_details_number':fitment_details_number,'adr_id':adr_id,'outrent_type':outrent_type,'details_rent_type':2,
                    'rentback_fix':rentback_fix,'rentback_nimb':rentback_nimb,'rentback_bond':rentback_bond,
                    'outrent_bill':outrent_bill,'outrent_bond':outrent_bond,'outrent_amount':outrent_amount
                },
                dataType:'json',
                success:function(res){
                    if(res.res=='ok'){
                        alert(res.msg);
                        history.go(0);
                    }else{
                        alert(res.msg);
                    }
                }
            });
        }
    </script>
@endsection
@section('content')
    <div id="content">
        @include('common.centernav')
        <h3>个人中心</h3>
        <div class="container">
            <div class="row">
            @include('usercenter.usersidebar')
                <!--2、右侧主体-->
                <div class="col-xs-9">
                    <!--右侧面版-->
                    <div id="panel" class="panel panel-default rightPanel">
                        <div class="panel-heading">
                            <h4 class="myorder">申请退租(组满即送)</h4>
                        </div>
                        <div class="panel-body">
                            <ul class="product list-inline">
                                <li>商品信息</li>
                                <li>订单金额</li>
                                <li>时长</li>
                                <li>退租数量</li>
                                <li>操作</li>
                            </ul>
                            @if(is_object($param['rentback_dt']))
                            <p class="productDate">
                                <span>下单日期:</span>
                                <span>{{substr($param['rentback_dt']->created_at,0,10)}}</span>&nbsp;&nbsp;
                                <span>订单号:</span>
                                <span>{{$param['rentback_dt']->details_orderNo}}</span>&nbsp;&nbsp;
                                <span>起租日期:</span>
                                <span>{{$param['rentback_dt']->details_fitment_start}}</span>
                                <a class="rt" href="{{url('/user/orderdt/'.$param['rentback_dt']->id)}}">订单详情</a>
                            </p>
                                <input type="hidden" name="order_id" value="{{$param['rentback_dt']->id}}">
                                <input type="hidden" name="order_details_id" value="{{$param['rentback_dt']->dtid}}">
                                <input type="hidden" name="details_orderNo" value="{{$param['rentback_dt']->details_orderNo}}">
                                <input type="hidden" name="details_fitment_id" value="{{$param['rentback_dt']->details_fitment_id}}">
                                <input type="hidden" name="rentback_num" value="{{$param['rentback_dt']->details_fitment_number}}">
                                <input type="hidden" name="rentback_fix" value="{{$param['rentback_dt']->details_fixprice}}">
                                <input type="hidden" name="rentback_nimb" value="{{$param['rentback_dt']->details_nimbleprice}}">
                                <input type="hidden" name="rentback_bond" value="{{$param['rentback_dt']->details_bond}}">
                                <input type="hidden" name="outrent_type" value="1">
                                <input type="hidden" name="adr_id" value="{{$param['rentback_dt']->adr_id}}">
                            <ul class="orders list-inline">
                                <li class="imgInfo">
                                    <div class="media">
                                        <div class="media-left">
                                            <img src="{{asset(env('STATIC_FILE_ERP_PATH').$param['rentback_dt']->fitment_details_imgMaster)}}" style="width: 151px;height: 92px;">
                                        </div>
                                        <div class="media-body">
                                            <p>{{$param['rentback_dt']->details_name}}</p>
                                            <p>
                                            <?php
                                            $color=DB::table('fitment_color')->where('color_details_id',$param['rentback_dt']->details_fitment_id)->select('color_type')->get();
                                            ?>
                                            @foreach($color as $color_k=>$color_v)
                                                <img src="{{$param['color'][$color_v->color_type]}}" alt="当前家具颜色">
                                            @endforeach
                                            </p>
                                            <p>¥<span>{{$param['rentback_dt']->details_fixprice}}</span>/月</p>
                                        </div>
                                    </div>
                                </li>
                                <li>¥{{$param['rentback_dt']->details_fixprice*$param['rentback_dt']->details_fitment_number}}</li>
                                <li><span>18</span>个月</li>
                                <li class="number">
                                    <b class="glyphicon glyphicon-minus-sign" onclick="decreback({{$param['rentback_dt']->dtid}})"></b>
                                    <span id="rentback_num">{{$param['rentback_dt']->details_fitment_number}}</span>
                                    <b class="glyphicon glyphicon-plus-sign" onclick="increback({{$param['rentback_dt']->dtid}})"></b>
                                </li>
                                <li>
                                    <span onclick="alert('删除功能需求还没确定')">&times;</span>
                                </li>
                            </ul>
                                @if($param['rentback_dt']->details_rent_type==1)
                                <div class="rent">
                                    <p>退租类型（租满即送）</p>
                                    <p>租满即送产品违约，已支付租期<span>2</span>月，未支付租期<span>3</span>，需支付违约金<span>{{$param['rentback_dt']->details_fixprice*18*0.05}}</span>元</p>
                                </div>
                                @endif
                            @endif
                            <p class="productDate border">未还款账单</p>
                            <ul class="list-inline noHead">
                                <li>还款期</li>
                                <li>时间</li>
                                <li>当前租金</li>
                            </ul>
                            @if(count($param['rentback_bill'])>0)
                            <?php $arr_bill=null;?>
                            @foreach($param['rentback_bill'] as $v)
                            <ul class="list-inline noBody">
                                <li>{{substr($v->months_bill,0,7)}}</li>
                                <li><span>18</span>个月</li>
                                <li class="red">¥<span>{{$v->amount}}</span></li>
                            </ul>
                                <?php $arr_bill+=$v->amount?>
                            @endforeach
                            @else
                            <ul class="text-center">
                                <img src="{{asset('/img/771509094256_.pic.jpg')}}" alt="暂无未付款记录">
                            </ul>
                            @endif
                            <p class="productDate border">退租说明</p>
                            <div class="introduce">
                                <p>对于"随租随还"的产品：</p>
                                <p>若您有退租需求可随时退租，但需缴纳退租产品的所有使用租金，芈租界会将产品押金退还至您的平台账户，可随时申请提现。</p>
                                <br>
                                <p>对于"租满即送"的产品：</p>
                                <p>若您有退租需求可进行申请，但视为违约行为，需向芈租界缴纳剩余未缴纳但租金5%作为违约金。</p>
                            </div>
                            <!--标签-->
                            <ul class="nav nav-tabs">
                                <li class="active" onclick="rentback_type(1)">
                                    <a href="#t1" data-toggle="tab">直接支付</a>
                                </li>
                                <li onclick="rentback_type(2)">
                                    <a href="#t2" data-toggle="tab">转随租随还</a>
                                </li>
                            </ul>
                            <!--创建内容组-->
                            <div class="tab-content">
                                <!--直接支付-->
                                <div class="tab-pane active" id="t1">
                                    <ul class="list-inline">
                                        <li value="1" class="active"><img src="/img/wx.png"><b></b></li>
                                        <li value="2"><img src="/img/zfb.png"><b></b></li>
                                        <li value="3"><img src="/img/yl.png"><b></b></li>
                                        <li value="4"><img src="/img/ye2.png"><b></b></li>
                                    </ul>
                                    <p class="accout" id="rentback_bill">
                                        <span>欠费账单：</span>
                                        <span class="money">¥</span>
                                        @if(count($param['rentback_bill'])>0)
                                        <span class="money">{{$arr_bill}}</span>
                                        @else
                                        <span class="money">0</span>
                                        @endif
                                    </p>
                                    <p class="accout" id="back_bond_t1">
                                        <span>违约金：</span>
                                        <span class="money">¥</span>
                                        <span class="money">{{$param['rentback_dt']->details_fitment_number*$param['rentback_dt']->details_fixprice*18*0.05}}</span>
                                    </p>
                                    <p class="accout" id="back_amount_t1">
                                        <span>需支付金额：</span>
                                        <span class="money">¥</span>
                                        @if(count($param['rentback_bill'])>0)
                                        <span class="money">{{$arr_bill+$param['rentback_dt']->details_fitment_number*$param['rentback_dt']->details_fixprice*18*0.05}}</span>
                                        @else
                                        <span class="money">{{$param['rentback_dt']->details_fitment_number*$param['rentback_dt']->details_fixprice*18*0.05}}</span>
                                        @endif
                                    </p>
                                </div>
                                <!--转随租随还-->
                                <div class="tab-pane" id="t2">
                                    <ul class="list-inline">
                                        <li value="5" class="active"><img src="/img/wx.png"><b></b></li>
                                        <li value="6"><img src="/img/zfb.png"><b></b></li>
                                        <li value="7"><img src="/img/yl.png"><b></b></li>
                                        <li value="8"><img src="/img/ye2.png"><b></b></li>
                                    </ul>
                                    <p class="accout">
                                        <span>欠费账单：</span>
                                        <span class="money">¥</span>
                                        @if(count($param['rentback_bill'])>0)
                                            <span class="money">{{$arr_bill}}</span>
                                        @else
                                            <span class="money">0</span>
                                        @endif
                                    </p>
                                    <p class="accout" id="back_bond_t2">
                                        <span>押金：</span>
                                        <span class="money">¥</span>
                                        <span class="money">{{$param['rentback_dt']->details_fitment_number*$param['rentback_dt']->details_nimbleprice*2}}</span>
                                    </p>
                                    <p class="accout" id="back_amount_t2">
                                        <span>需支付金额：</span>
                                        <span class="money">¥</span>
                                        @if(count($param['rentback_bill'])>0)
                                        <span class="money">{{$arr_bill+$param['rentback_dt']->details_fitment_number*$param['rentback_dt']->details_nimbleprice*2}}</span>
                                        @else
                                        <span class="money">{{$param['rentback_dt']->details_fitment_number*$param['rentback_dt']->details_nimbleprice*2}}</span>
                                        @endif
                                    </p>
                                </div>
                            </div>
                            <div class="btnName">
                                <a class="btn btn-danger" onclick="dorentback_type_fix()">确认退租</a>
                                <a class="btn btn-warning" onclick="alert('等待研发')">联系客服</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
